angular.module('mamApp').factory('BaseValidations', ['$http', function ($http) {
    /*
     用途：校验关键词
     长度：每个关键词1-12字符
     数量：不超过5个关键词
     每个关键词之间，用英文状态下","做区隔
     */
    function checkKeyword(keyword) {
        var regChinese = /^([\u4E00-\u9FA5]+，?)+$/;//纯中文
        var regEng = /[a-zA-Z0-9]*/;//英文和数字
        var regEngCh=/^([\u4e00-\u9fa5]{1,4}|[a-zA-Z0-9]{1,12})$/g ;//

        if (keyword && (typeof keyword) == "string") {
            keyword=keyword.replace(/，|；|;|、|\s/g,",");
            var words = keyword.split(",");
            console.log(words)
            if (words.length > 5) {
                return false;
            } else {
                var pass = true;
                words.forEach(function (word) {
                    console.log(word)
                    if (!word.match(regEngCh)) {
                        pass = false;
                    }
                })
                return pass;
            }
        } else {
            return true
        }
    }

    function checkKeywordA(keyword) {
        if (keyword && (typeof keyword) == "string") {
            keyword=keyword.replace(/，|；|;|、|\s/g,",");

            var words = keyword.split(",");

            if (words.length > 5) {
                return false;
            } else {
                var pass = true;
                words.forEach(function (word) {
                    console.log(word)
                    if (!word.length > 20 || word.length < 2) {
                        pass = false;
                    }
                })
                return pass;
            }

        } else {
            return true
        }
    }
    /*
     用途：校验关键词
     长度：每个关键词1-12字符
     数量：不超过5个关键词
     每个关键词之间，用英文状态下","做区隔
     */
    function checkTags(keyword) {
        var regEngCh=/^([\u4e00-\u9fa5]{1,6}|[a-zA-Z]{1,12})$/g ;
        if (keyword && (typeof keyword) == "string") {
            keyword=keyword.replace(/，|；|;|、|\s/g,",");
            var words = keyword.split(",");
            console.log(words)
                var pass = true;
                words.forEach(function (word) {
                    if (!word.match(regEngCh)) {
                        pass = false;
                    }
                })
                return pass;


        } else {
            return true
        }
    }

    function checkLicenseUrl(url) {
        return url ? true : false;
    }


    /*
     用途：校验主播
     长度：每个2-20字符
     数量：不超过5个主播不能为空
     每个关键词之间，用英文状态下","做区隔
     */
    function checkAnchorName(keyword) {
        if (keyword && (typeof keyword) == "string") {
            keyword=keyword.replace(/，|；|;|、|\s/g,",");
            var words = keyword.split(",");
            if (words.length > 5) {
                return false;
            } else {
                var pass = true;
                words.forEach(function (word) {
                    if (word.length > 20 || word.length < 2) {
                        pass = false;
                    }
                })
                return pass;
            }
        } else {
            return false
        }

    }

    /*
     用途：校验节目的主播
     长度：每个关键词2-20字符
     数量：不超过5个主播不能为空
     每个关键词之间，用英文状态下","做区隔
     */
    function checkProgrammeAnchorName(keyword) {
        if (keyword && (typeof keyword) == "string") {
            keyword=keyword.replace(/，|；|;|、|\s/g,",");
            var words = keyword.split(",");
            if (words.length > 5) {
                return false;
            } else {
                var pass = true;
                words.forEach(function (word) {
                    if (word.length > 20 || word.length < 2) {
                        pass = false;
                    }
                })
                return pass;
            }
        } else {
            return true;
        }

    }


    return {
        checkKeyword: checkKeyword,//关键词
        checkKeywordA: checkKeywordA,//关键词
        checkTags:checkTags,
        checkAnchorName: checkAnchorName, //关键词
        checkLicenseUrl: checkLicenseUrl,
        checkProgrammeAnchorName: checkProgrammeAnchorName//关键词
    };
}]);
